package com.ma.myjpa.demo;

import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.*;

/**
 * @ClassName TestJDBC
 * @Author: mayongqiang
 * @DATE 2022/4/13 15:39
 * @Description:
 */
public class TestJDBC {
    static BasicDataSource dataSource = new BasicDataSource();
    static String driver = "com.mysql.jdbc.Driver";
    static String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false";
    static String username = "root";
    static String password = "123456";

    static {
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
    }

    private static JdbcTemplate template = new JdbcTemplate(dataSource);

    public static void main(String[] args) throws SQLException {
        String sql = "insert into user (id,name) values (?,?)";
        try (Connection connection = DriverManager.getConnection(url, username, password);) {
            try (PreparedStatement ps = connection.prepareStatement(sql)){
                ps.setObject(1,5);
                ps.setObject(2,"box");
                ps.executeUpdate();
            }finally{
                connection.close();
            }
        }



}
}
